#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int a[N];
vector<int> st[N];
void solve() {
  cin >> n >> m;
  rep(i, 1, m) st[i].clear();
  rep(i, 1, n) {
    int len;
    cin >> len;
    rep(j, 1, len) {
      int x;
      cin >> x;
      if (st[x].size() && st[x].back() == i)
        continue;
      else
        st[x].push_back(i);
    }
  }
  set<int> need;
  rep(i, 1, m) {
    if (st[i].empty()) {
      cout << "NO" << endl;
      return;
    } else if (st[i].size() == 1)
      need.insert(st[i][0]);
  }
  int x = n - need.size();
  if (x < 2)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}